const fs = require('fs');
const path = require('path');
const semver = require('semver');
const yParser = require('yargs-parser');
const program = require('commander');
const ora = require('ora');
const exec = require('child_process').execSync
const run = require('../lib/run.js')
const { version } = require('../package.json') ;
const args = yParser(process.argv.slice(2));
if (!semver.satisfies(process.version, '>= 8.0.0')) {
    console.error(chalk.red('✘ The generator will only work with Node v8.0.0 and up!'));
    process.exit(1);
}

const name = args._[0] || '';
const type = args._[1] || '';

// 版本更新提示
// 获取当前安装的版本和最新版本
let version_lists = (exec('npm view edaoe-cli versions --json') + "").split('\n');
let lasted_version = version_lists[version_lists.length-3];
if(lasted_version.replace(/\"/g, '').replace(/" "/g, '') != version) {
    console.log(`
        lasted_version ===> ${lasted_version.replace(/\"/g, '').replace(/" "/g, '')},
        current_version ===> ${version}
        ==================================
        ctrl+c  ❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
        npm i edaoe-cli -g
        ==================================
    `);
}

program.version(version,'-v --version').parse(process.argv);  //加 option
run({
    name,
    type,
    args,
  });